package itsm.isperp.module.controller.db;

import javax.servlet.http.HttpServletRequest;

import itsm.isperp.framework.web.response.ResultMessage;
import itsm.isperp.module.service.db.DbDataManageService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * 数据维护控制器，包括对数据的备份、还原、清理、运行情况等
 * 
 * @author lizx
 * @date 2014-6-14
 * @since 1.0
 * 
 */
@Controller
@RequestMapping("db/dataManage")
public class DbDataManageController {

	@Autowired
	DbDataManageService dbDataManageService;

	/**
	 * 管理界面
	 * 
	 * @return 菜单管理界面视图
	 */
	@RequestMapping(value = { "manage", "" })
	public ModelAndView manage(HttpServletRequest req) {
		ModelAndView mv = new ModelAndView("db/dataManage/manage");

		return mv;
	}

	/**
	 * 备份数据（不包含数据结构）
	 * 
	 * @return
	 */
	@RequestMapping("backupData")
	@ResponseBody
	public ResultMessage backupData() {
		try {
			dbDataManageService.backupData();
		} catch (Exception e) {
			return ResultMessage.failure(e);
		}
		return ResultMessage.success();
	}

	/**
	 * 清理业务数据
	 * 
	 * @return
	 */
	@RequestMapping("clearBusinessData")
	@ResponseBody
	public ResultMessage clearBusinessData() {
		dbDataManageService.clearBusinessData();
		return ResultMessage.success();
	}

}
